package com.mx.restful.view.window.options;

import com.intellij.util.ui.FormBuilder;
import org.jetbrains.annotations.NotNull;

import javax.swing.*;
import java.awt.*;

/**
 * @Author: mengxiang.
 * @Date: 2020/6/22.
 * @Time: 11:37 上午.
 * @Description:
 */
public class OptionForm {

    private final FormBuilder formBuilder;

    private JPanel content;
    private JLabel titleName;
    private JPanel optionItem;

    public OptionForm(@NotNull String titleName) {
        this.titleName.setText(titleName);
        formBuilder = FormBuilder.createFormBuilder();
    }

    protected final void addOptionItem(@NotNull JComponent component) {
        formBuilder.addComponent(component);
    }

    protected final void addOptionItem(@NotNull JComponent component, int topInset) {
        formBuilder.addComponent(component, topInset);
    }

    protected final void addLabeledOptionItem(@NotNull String name, @NotNull JComponent component) {
        formBuilder.addLabeledComponent(name, component);
    }

    protected final void addLabeledOptionItem(@NotNull String name, @NotNull JComponent component, int topInset) {
        formBuilder.addLabeledComponent(name, component, topInset);
    }

    protected final void addLabeledOptionItem(@NotNull String name, @NotNull JComponent component, boolean labelOnTop) {
        formBuilder.addLabeledComponent(name, component, labelOnTop);
    }

    public final JComponent getContent() {
        optionItem.add(formBuilder.getPanel(), BorderLayout.CENTER);
        return content;
    }
}
